/*
 * Pawn.cpp
 *
 *  Created on: Mar 6, 2011
 *      Author: Michael Ziminsky
 */

#include "Pawn.h"

namespace model
{
    namespace piece
    {
        Pawn::Pawn(bool light) : ChessPiece(light){};

        globals::moveSet Pawn::getPotentialMoves(const ChessBoard& b) const
        {
            globals::moveSet moves(new globals::moveSet::element_type);
            if (currLoc)
            {
                int dir = isLight ? 1 : -1;
                cellCheck(b, getOffsetLocation(UP, *currLoc, dir), moves);
                if (((isLight && currLoc->row == 2) || (!isLight && currLoc->row == 7)) && moves->size() == 1)
                        cellCheck(b, getOffsetLocation(UP, *currLoc, 2 * dir), moves);
                cellCheck(b, getOffsetLocation(LEFTUP, *currLoc, dir), moves);
                cellCheck(b, getOffsetLocation(RIGHTUP, *currLoc, dir), moves);
            }
            return moves;
        }

        bool Pawn::cellCheck(const ChessBoard& b, const Location& l, globals::moveSet& moves) const
        {
            unsigned int initSize = moves->size();
            bool cont = ChessPiece::cellCheck(b, l, moves);
            if ((cont && l.col != currLoc->col) || (!cont && l.col == currLoc->col && initSize < moves->size())) moves->erase(MovePiece(*currLoc, l, cont));
            return cont;
        }
    }
} // namespace model
